<template>
	<view class="container">
		<view class="title">
			<input v-model="itemMsg.title" placeholder="请输入教案标题" />
		</view>
		<view class="note">
			<textarea v-model="itemMsg.note" maxlength='-1' placeholder="请输入教案内容文案" />
		</view>
		<view class="button" @click="save">发布</view>
		<view class="text_tips" v-if="list.length>0">我已发布的内容</view>
		<view class="preparationUpload-list">
			<mark-slide-list :list="list" :button="buttonList" :border="true" @click="goitem"
				@change="changeMethod"></mark-slide-list>
		</view>
	</view>
</template>

<script>
	import {
		getTeacherhelperContents,
		getTeacherhelperContentsOne,
		getTeacherhelperContentsSend,
		getTeacherhelperContentDel
	} from "../../../static/js/api/preparation.js";
	import markSlideList from '../../../components/mark-slide-list/mark-slide-list.vue'
	export default {
		components: {
			markSlideList
		},
		data() {
			return {
				itemMsg: {
					title: '',
					note: '',
				},
				list: [],
				buttonList: [{
					title: '删除',
					background: '#ff3b32'
				}],
			}
		},
		onLoad() {
			this.getData()
		},
		methods: {
			goitem(item){
				uni.navigateTo({
					url:"/pages/releasePlan/preparation/listDetails?itemId="+item.id
				})
			},
			changeMethod(data, button, index) {
				let _this = this
				if(button.title=='删除'){
					uni.showModal({
						title: '提示',
						content: '确定删除？',
						confirmColor:'#FF6E00',
						success: function (res) {
							if (res.confirm) {
								getTeacherhelperContentDel({
									id:data.id
								}).then(res=>{
									_this.getData()
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
			},
			getData(){
				getTeacherhelperContents({
					page:1
				}).then(res=>{
					console.log(res)
					if(res.contents){
						res.contents.forEach(item=>{
							item.slide_x = 0
							item.image = require('../../../static/imgs/mine/edit.png')
						})
						this.list = res.contents
					}
				})
			},
			save(){
				if(this.itemMsg.title.length==0){
					uni.showToast({
						icon:'none',
						title:"请输入教案标题"
					})
					return
				}
				if(this.itemMsg.note.length==0){
					uni.showToast({
						icon:'none',
						title:"请输入教案内容文案"
					})
					return
				}
				getTeacherhelperContentsSend({
					title:this.itemMsg.title,
					content:this.itemMsg.note
				}).then(res=>{
					this.getData()
					this.itemMsg.title = ''
					this.itemMsg.note = ''
					uni.showToast({
						icon:'none',
						title:"发布成功"
					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import url("../index.scss");

	.text_opblack {
		color: $uni-text-color-opblack;
	}

	.text_black {
		color: $uni-text-color-black;
	}

	.text_active {
		color: $uni-color-primary;
	}

	.button {
		margin: 40rpx auto;
	}

	.text_tips {
		font-size: 24rpx;
		font-weight: 400;
		color: $uni-text-color-opblack;
		padding: 0 30rpx;
		margin-bottom: 20rpx;
	}
	.preparationUpload-list /deep/ .icon-image{
		width: 48rpx!important;
		height: 48rpx!important;
	}
</style>